const express=require('express')

const app=express()
const data=require('./mock/data.json')


const fs=require('fs')
app.use(express.static('../list'))
app.get('/detail',(req,res)=>{
    
   res.end(
      fs.readFileSync('../list/detail.html')
   )
    
})
// 列表渲染
app.get('/api/data',(req,res)=>{
    res.send({
        code:200,
        data:data.list
    })
})
// 详情页
app.get('/api/detail',(req,res)=>{
    const {id}=req.query
    res.send({
        code:200,
        data1:data.list.find(item=>item.id===id)
    })
})
// 模糊搜索
app.get('/api/seach',(req,res)=>{
    const {value}=req.query
    let seachvalue=data.list.filter(v=>v.title.includes(value))
    res.send({
        code:200,
        data:seachvalue
    })

})
app.listen(8080,()=>console.log('峰'))